#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include "bmp.h"

struct fileInfo
{
    int width;
    int height;
    int bpp;   // bits per pixel
    char *rgb;
};

int main(int argc, char const *argv[])
{
    // 打开目录
    DIR *dp = opendir(argv[1]);
    // 进入目录
    chdir(argv[1]);

    struct dirent *ep;
    while(1)
    {
        ep = readdir(dp); // 目录项（文件）指针

        if(ep == NULL)
            break;

        // 判断是否是bmp文件
        if(strstr(ep->d_name, ".bmp"))
        {
            FILE *fp = fopen(ep->d_name, "r");

            struct bitmap_header header;
            struct bitmap_info   info;
            fread(&header, sizeof(header), 1, fp);
            fread(&info,   sizeof(info),   1, fp);
            fclose(fp);

            printf("%s: %d×%d\n", ep->d_name, info.width, info.height);
        }
    }
    return 0;
}
